import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.List;

public class GameState {
	
	List<InputKeyListener> mKeyListeners;
	
	public GameState() {
		
		mKeyListeners = new ArrayList<InputKeyListener>();
		
	}
	
	public void addInputKeyListener(int keyCode, Runnable runnable, String commandDescription){
		mKeyListeners.add(new InputKeyListener(keyCode, runnable, commandDescription));
	}
	
	public List<InputKeyListener> getListeners() {
		return mKeyListeners;
	}
	

	class InputKeyListener implements KeyListener, DisplayableInput {

		private int mKeyCode;
		private Runnable mRunnable;
		private String mCommandDescription;

		public InputKeyListener(int keyCode, Runnable runnable, String commandDescription) {
			mKeyCode = keyCode;
			mRunnable = runnable;
			mCommandDescription = commandDescription;
		}

		@Override
		public void keyTyped(KeyEvent e) {
			// Not used
		}

		@Override
		public void keyPressed(KeyEvent e) {
			if (e.getKeyCode() == mKeyCode) {
				mRunnable.run();
			}
		}

		@Override
		public void keyReleased(KeyEvent e) {
			// Not used
		}

		@Override
		public int getKeyCode() {
			return mKeyCode;
		}

		@Override
		public String getCommandDescription() {
			return mCommandDescription;
		}

	}

}
